package com.cn.common.util;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * 通过此工具类获取请求、响应等对象
 */
public class ServletUtil {

    /**通过 spring 提供的RequestContextHolder获取请求属性*/
    private static ServletRequestAttributes getServletRequestAttributes() {
        return (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    }
    /**获取请求对象*/
    public static HttpServletRequest getRequest(){
        return getServletRequestAttributes().getRequest();
    }
}
